perm filename A102.TEX[106,RWF]1 blob
sn#807801 filedate 1985-10-07 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \magnification\magstephalf
C00008 ENDMK
Cā;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a102.tex[106,phy] \today\hfill}
\font\rmn=amr9
\bigskip
\line{(Assumes conditionals, assignment)\hfil}
{\rmn
{\narrower\smallskip\noindent
{\bf Exercise:} ({\tt DIV} and {\tt MOD}) (or use as example?)
A bank represents the amounts of accounts, checks, deposits, etc., by integers,
using cents rather than dollars within the computer program. Design a procedure
to print such integers as dollar amounts in legible form; for example,
12345678 would be printed as \$123,456.78, and 12 would be printed as \$0.12.
\smallskip}
}
{\rmn
{\narrower\smallskip\noindent
{\bf Solution.}
\smallskip}
}
\smallskip
{\obeylines\obeyspaces\let =\ \tt
PROCEDURE DOLLARPRINT(CENTS:INTEGER);
VAR COUNT, POSITION, I: INTEGER;
\smallskip
BEGIN
COUNT:=3; POSITION:=100;
\smallskip
WHILE CENTS>=10*POSITION DO
BEGIN
POSITION:=10*POSITION;
COUNT:=COUNT +1
END;
WRITE ('\$');
FOR I:=COUNT DOWNTO 1 DO
BEGIN
WRITE(CENTS DIV POSITION:1);
CENTS:=CENTS MOD POSITION;
POSITION:=POSITION DIV 10;
IF I=3 THEN WRITE ('.')
ELSE IF I MOD 3=0 THEN WRITE (',')
END
END;
}
\smallskip
{\rmn
{\narrower\smallskip\noindent
The first half of this program, {\tt POSITION} is set to the place value
of the first decimal digit needed, and {\tt COUNT} is the number of digits
needed. The program may fail by {\tt 10*POSITION} exceeding {\tt MAXINT}.
\smallskip}
}
\bigskip
\line{\copyright 1984 Robert W. Floyd;
First draft (not published) May 16, 1984\hfil}
%revised: Date; subsequently revised.\hfill}
\bye